package com.xiaoma.suanfa.leetcode;

import java.util.PriorityQueue;
import java.util.concurrent.PriorityBlockingQueue;

/**
 * https://leetcode-cn.com/problems/last-stone-weight/solution/zui-hou-yi-kuai-shi-tou-de-zhong-liang-b-xgsx/
 * 最后一块石头
 */
public class Stone {
    public static int lastStoneWeight(int[] stones) {
        PriorityQueue<Integer> pq = new PriorityQueue<Integer>((a, b) -> b - a);
        for (int stone : stones) {
            pq.offer(stone);
        }

        while (pq.size() > 1) {
            int a = pq.poll();
            int b = pq.poll();
            if (a > b) {
                pq.offer(a - b);
            }
        }

        return pq.isEmpty() ? 0 : pq.poll();
    }

    public static int lastStoneWeight(String[] stones) {
        PriorityBlockingQueue<Integer> pq = new PriorityBlockingQueue<Integer>();
        pq.add(2342);

        return pq.isEmpty() ? 0 : pq.poll();
    }

    public static void main(String[] args) {
        int[] array={3,4,2,5};
        int i = lastStoneWeight(array);
        System.out.println(i);
    }

}
